package com.estar.assistsurvy.widget;


import com.estar.assistsurvy.R;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;

public class SelectPicPopupWindow extends PopupWindow {
private Button take_photo,pick_photo,cancel;
private View v;
public SelectPicPopupWindow(Context context,OnClickListener albumClick,OnClickListener graphClick){
	super(context);
	LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	v=inflater.inflate(R.layout.takephoto_layout, null);
	take_photo=(Button) v.findViewById(R.id.take_photo);
	pick_photo=(Button) v.findViewById(R.id.pick_photo);
	cancel=(Button) v.findViewById(R.id.cancel);
	cancel.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			dismiss();
		}
	});
	
	take_photo.setOnClickListener(graphClick);
	pick_photo.setOnClickListener(albumClick);
	pick_photo.setVisibility(View.GONE);
	this.setContentView(v);
	this.setWidth(LayoutParams.MATCH_PARENT);
	this.setHeight(LayoutParams.WRAP_CONTENT);
	this.setFocusable(true);
	this.setAnimationStyle(android.R.style.Animation);
	ColorDrawable dw=new ColorDrawable(0xb0000000);
	this.setBackgroundDrawable(dw);
	v.setOnTouchListener(new OnTouchListener() {
		@Override
		public boolean onTouch(View v, MotionEvent event) {
			int height=v.findViewById(R.id.pop_layout).getTop();
			int y=(int) event.getY();
			if(event.getAction()==MotionEvent.ACTION_UP){
				if(y<height){
					dismiss();
				}
			}
			return true;
		}
	});
}
	
	
	
	
	
	
	
	
	
	
}
